<?php

/*	Vulpes - Web-based managegent for wireless internet providers.
	Copyright (C) 2007 Alwin Garside

	This file is part of Vulpes.

	Vulpes is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Vulpes is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>. */

switch(get('action'))
{
	case 'arp':
		$arp_sql = '
			SELECT `clients`.`username`, `contracts`.`ip`
			FROM `clients`
			INNER JOIN `contracts` ON (
				`clients`.`username` = `contracts`.`client_username` )';
		if(!$result_clients = $db->query($arp_sql)) break;
		$clients = array();
		while ($client = $result_clients->fetch_object())
		{
			$clients[$client->ip] = $client->username;
		}
		$result_clients->free();
	
		$arp = arp();

		$page->content .= '<arp>';
		foreach ($arp as $machine) {
			$page->content .= '<machine>';
			$page->content .= '<username>'.$clients[$machine['ip_address']].'</username>';
			$page->content .= xml_iterate($machine);
			$page->content .= '</machine>';
		}
		$page->content .= '</arp>';
		break;

	case 'ping':
		$output = array();
		exec('ping -W 5 -c 1 '.get('host'), $output);
		$page->content .= '
			<ping>
				<host>'.get('host').'</host>
				<ping1>'.$output[1].'</ping1>
				<ping2>'.$output[3].'</ping2>
			</ping>';
		break;

	case 'squid':
		$output = array();
		exec('tail -n50 /var/log/squid/access.log', $output);
		$page->content .= '<squid>';
		foreach ($output as $value) {
			$page->content .= '<line>'.$value.'</line>';
		}
		$page->content .= '</squid>';
		break;
		
}

?>